/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#include <qprocess.h>
#include <qsqlquery.h>
#include <qsqlrecord.h>
#include <qsqlresult.h>
#include <qmessagebox.h>
#include <qtextcodec.h>
#include <qsqlrecord.h>
#include <qsqlselectcursor.h>
#include "notatki_form.h"
#include "SQLquery_form.h"
#include <stdlib.h>


//otwiera formatke notatki_form
void Form2::dodajNotatke()
{
 Form3 *notatki_form= new Form3;
  notatki_form->show();
 }

//otwiera formatke SQLquery_form
void Form2::otworzSQLquery()
{
 Form4 *SQLquery_form= new Form4;
  SQLquery_form->show();
}
//filtry do tabeli lokale
void Form2::WyszukajPoNrLok()
{
QString filter1="id_lokalu like '%"+lineNrLok->text()+"%'";
    dataTableLok->setFilter(filter1);
     dataTableLok->refresh();
     lineNrLok->clear();
}

void Form2::WyszukajPoUlicy()
{
QString filter2="ulica like '%"+ lineUlica->text()+"%'";
dataTableLok->setFilter(filter2);
dataTableLok->refresh();
lineUlica->clear();
}

//filtry do tabeli mieszkancy
void Form2::WyszukajPoNrLokMiesz()
{
QString filter3="id_lokalu like '%"+lineNrLokMiesz->text()+"%'";
dataTableMiesz->setFilter(filter3);
dataTableMiesz->refresh();
lineNrLokMiesz->clear();
}

void Form2::WyszukajPoNazwisku()
{
QString filter4="nazwisko like '%"+lineNazw->text()+"%'";
dataTableMiesz->setFilter(filter4);
dataTableMiesz->refresh();
lineNazw->clear();
}

//filtry dla tabeli oplaty
void Form2::WyszukajPoNrLokOpl()
{
QString filter5="id_lokalu like '%"+lineEditOplNrLok->text()+"%'";
dataTableOpl->setFilter(filter5);
dataTableOpl->refresh();
lineEditOplNrLok->clear();
}

//filtry dla tabeli wplaty
void Form2::pokaz_niezaplacili()
{
QString filter6="status=false";
    dataTableWpl->setFilter(filter6);
     dataTableWpl->refresh();
}


void Form2::pokaz_zaplacili()
{
QString filter7="status=true";
    dataTableWpl->setFilter(filter7);
     dataTableWpl->refresh();
}

//mesagebox o programie
void Form2::oprogramie()
{
QMessageBox::about (this, "Qspoldzielnia v0.0.1 beta",
        "Program do obslugi wspoldzielni mieszkaniowej. \n Koordynatorzy projektu: \n\tMarcin Miasik \n\tMarek Celinski \n");	
}


//QProcess *process;
/*
void Form2::archiwizuj()
{
process = new QProcess (this);
 
//process->addArgument ("./backup.sh");
process->addArgument ("pg_dump");
process->addArgument ("-d");
process->addArgument ("spolnota");
process->addArgument ("-f");
process->addArgument ("arch.sql");
connect( process, SIGNAL(readyReadStderr()),
                this, SLOT(readFromStdout()) );
connect(process, SIGNAL(processExited()),
	this, SLOT(processExited()));
process->start();
}

void Form2::readFromStdout()
{
    process->readStderr();
}

void Form2::processExited()
{
    process->normalExit();
    delete process;
    process = 0;
}
*/

void Form2::czynsz()
{
   QSqlSelectCursor* licz = new QSqlSelectCursor("select oblicz()");
   dataTableOpl->setSqlCursor( licz, TRUE, TRUE );

   QSqlSelectCursor* licz2 = new QSqlSelectCursor("select * from oplaty");
   dataTableOpl->setSqlCursor( licz2, TRUE,TRUE);

}


void Form2::interaktywny()
{
    bool * ok = 0;
   QString zczyt=QLineEditPowierzchnia_2->text();
   float ls= zczyt.toFloat (ok); 
   QString zczyt2=QLineEditCena_m2->text();
   float ls2=zczyt2.toFloat (ok);
   float wynik=ls*ls2;
   QLineEditCzynsz->setText( QString::number(wynik));
delete ok;   
}
